<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
</head>

<body>
    <script>
        // WxhideOptionMenu
        var APPID = "wx92e23e5b5cfee7c3"
        var code = GetQueryValue("code")
        var state = GetQueryValue("state")
        if (code) {
            console.log(code)
            console.log(state)
        } else {
            location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${APPID}&redirect_uri=${encodeURIComponent(location.href)}&response_type=code&scope=snsapi_userinfo&state=${state || 123}&connect_redirect=1#wechat_redirect`
        }

        /**
         * [获取URL中的参数名及参数值的集合]
         * 示例URL:http://htmlJsTest/getrequest.html?uid=admin&rid=1&fid=2&name=小明
         * @param {[string]} urlStr [当该参数不为空的时候，则解析该url中的参数集合]
         * @return {[string]}       [参数集合]
         */
        function GetRequest(urlStr) {
            if (typeof urlStr == "undefined") {
                var url = decodeURI(location.search); //获取url中"?"符后的字符串
            } else {
                var url = "?" + urlStr.split("?")[1];
            }
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
                }
            }
            return theRequest;
        }


        /**
         * [通过参数名获取url中的参数值]
         * 示例URL:http://htmlJsTest/getrequest.html?uid=admin&rid=1&fid=2&name=小明
         * @param  {[string]} queryName [参数名]
         * @return {[string]}           [参数值]
         */
        function GetQueryValue(queryName) {
            var reg = new RegExp("(^|&)" + queryName + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return decodeURI(r[2]);
            } else {
                return null;
            }
        }
    </script>
</body>

</html>